package com.springboot.elaticsearch.demo.controller;


import com.springboot.elaticsearch.demo.service.IDmAllplatOrderCompanyCountDayService;
import com.springboot.elaticsearch.demo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 企业销售统计表 前端控制器
 * </p>
 *
 * @author jxm
 * @since 2023-03-01
 */
@RestController
@RequestMapping("/company")
public class DmAllplatOrderCompanyCountDayController {

    @Autowired
    IDmAllplatOrderCompanyCountDayService companyCountDayService;

    @GetMapping("/toes")
    public boolean saveToES(){
        return companyCountDayService.saveToES();
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String,Object>> search(@PathVariable("keyword") String keyword,
                                           @PathVariable("pageNo") Integer pageNo,
                                           @PathVariable("pageSize") Integer pageSize) throws IOException {
        return companyCountDayService.search(keyword,pageNo,pageSize);
    }


    @GetMapping("/searchPage/{pageNo}/{pageSize}")
    public List<PageUtils> searchPage(@RequestParam("keyword") String keyword,
                                           @PathVariable("pageNo") Integer pageNo,
                                           @PathVariable("pageSize") Integer pageSize) throws Exception {

        PageUtils search = companyCountDayService.searchPage(keyword,pageNo, pageSize);
        List<PageUtils> list = new ArrayList<>();
        list.add(search);
        return list;
    }
}
